home *** CD-ROM | disk | FTP | other *** search
/ The Very Best of Atari Inside / The Very Best of Atari Inside 1.iso / mint / mntlib43 / mntlib / waitpid.c < prev    next >
C/C++ Source or Header  |  1993-10-26  |  1KB  |  71 lines

  1. /* waitpid() emulation for MiNT, by Howard Chu. From wait3.c by Eric R. Smith
  2.  */
  3.  
  4. #include <types.h>
  5. #include <wait.h>
  6. #include <time.h>
  7. #include <resource.h>
  8. #include <mintbind.h>
  9. #include <errno.h>
  10. #include <signal.h>
  11.  
  12. extern int __mint;
  13.  
  14. extern long __waitval;        /* in thread.c */
  15.  
  16. pid_t
  17. waitpid(pid, _status, options)
  18.     pid_t pid;
  19.     __WP _status;
  20.     int options;
  21. {
  22.     long r;
  23.     int exit_status, sig_term;
  24.     union wait *statwait;
  25. #ifdef _EXPERIMENTAL_WAIT_MACROS
  26.     int *status = _status.__wi;
  27. #else
  28.     int *status = _status;
  29. #endif    
  30.  
  31.     statwait = (union wait *) status;
  32.     if (__mint == 0) {
  33.         r = __waitval;
  34.         __waitval = -ENOENT;
  35.     } else
  36.         r = Pwaitpid(pid, options, 0L);
  37.     if (r < 0) {
  38.         errno = (int) -r;
  39.         return -1;
  40.     }
  41.     pid = (int) ((r & 0xffff0000L) >> 16);
  42.     if (pid) {
  43.       if (statwait)
  44.         {
  45.         statwait->_i = 0;
  46.  
  47.         if ( ((short)r) == -32) {
  48.             sig_term = SIGINT;
  49.             exit_status = 0;
  50.         }
  51.         else {
  52.             exit_status = (int) (r & 0x000000ffL);
  53.             sig_term = (int) ((r & 0x00007f00L) >> 8);
  54.         }
  55.         if (sig_term >= NSIG)
  56.           sig_term = 0;
  57.         if (sig_term && exit_status != 0 && exit_status != 0177)
  58.             sig_term = 0;
  59.         if (exit_status == 0177 && sig_term) {
  60.             statwait->w_termsig = WSTOPPED;
  61.             statwait->w_stopsig = sig_term;
  62.         }
  63.         else {
  64.             statwait->w_termsig = sig_term;
  65.             statwait->w_retcode = exit_status;
  66.         }
  67.         }
  68.     }
  69.     return pid;
  70. }
  71.